<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
      s{
          margin: 0px;
          padding: 0px;
          list-style: none;
      }
      div{
          width:520px;
          height: 280px;
          margin:100px auto;
          position: relative;
          overflow: hidden;
      }
      .wa{
          width: 9999px;
      }
      .wal{
          float: left;
      }
     .po{
          position: absolute;
          bottom: 20px;
          left:50px;
          transform:translateX(-50%)
      }
      .pok{
          width: 8px;
          height: 8px;
          background: white;
          border-radius: 50%;
          margin: 0px 4px;
          float:left;
          cursor: pointer;
      }
      span{
          position: absolute;
          background: palevioletred;
          top:50%;
          transform: translateY(-50%);
          cursor: pointer;
      }
      span:nth-of-type(1){
          left:10px;
      }
      span:nth-of-type(2) {
          right:10px;
      }
     .jiji{
         background:palevioletred ;
     }

    </style>
</head>
<body>
    <div id="wrap">
        <ul id="box">
            <li>
                <img src="images/ttt1.jpg" alt="">
            </li>
            <li>
                <img src="images/ttt2.jpg" alt="">
            </li>
            <li>
                 <img src="images/ttt3.jpg" alt="">
            </li>
            <li>
                <img src="images/ttt4.jpg" alt="">
            </li>
        </ul>
        <ol id="list">
            <li class="jiji"></li>
            <li></li>
            <li></li>
            <li></li>

        </ol>
        <span id="left">左</span>
        <span id="right">右</span>
    </div>
    <script>
        var box=document.getElementById('box');
        var wrap=document.getElementById('wrap');
        var right=document.getElementById('right');
        var left=document.getElementById('left');
        var list=document.getElementById('list').children
        var num=0;
        var timer;
        function fn(){
            timer=setInterval(function(){
            num++;
            if(num>3){
                num=0;
            }
            var t=-num*520;
            box.style.transform='translateX('+t+'px)';
            for(var j=0;j<list.length;j++){
                list[j].className='';
            }
            list[num].className='jiji'

        },1000)
        }
        fn()
        wrap.onmouseenter=function(){
            clearInterval(timer)
        }
        wrap.onmouseleave=function(){
            fn()
        }
        for(var i=0;i<list.length;i++){
            list[i].index=i;
                list[i].onclick=function(){
                    for(var j=0;j<list.length;j++){
                        list[j].className='';
                    }
                    this.className='jiji';
                    num=this.index;
                    var t=-num*520;
                    box.style.transform='translateX('+t+'px)';
                }
        }
        right.onclick=function(){
                num++;
                if(num>3){
                    num=0;
                }
                var t=-num*520;
                box.style.transform='translateX('+t+'px)';
                for(var j=0;j<list.length;j++){
                        list[j].className='';
                    }
                    list[num].className=''
            }
            left.onclick=function(){
                num--;
                if(num<0){
                    num=3;
                }
                var t=-num*520;
                box.style.transform='translateX('+t+'px)';
                for(var j=0;j<list.length;j++){
                        list[j].className='';
                    }
                    list[num].className='jiji'
            }

    </script>
</body>
</html>